package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.HotelTheme;
import cn.wolfcode.luowowo.article.mapper.HotelThemeMapper;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IHotelThemeService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class HotelThemeServiceImpl implements IHotelThemeService {
    @Autowired
    private HotelThemeMapper hotelThemeMapper;
    @Reference
    private IDestinationService destinationService;
    public List<HotelTheme> selectList() {
        List<HotelTheme> hotelThemes = hotelThemeMapper.selectList();
        for(HotelTheme ht:hotelThemes){
            if("周末好去处".equals(ht.getName())){
                continue;
            }
            List<Object> list = new ArrayList<>();
            for(long destId:ht.getDestIds()){
                Destination dest = destinationService.getById(destId);
                list.add(dest);
            }
            ht.setDests(list);
        }
        return hotelThemes;
    }

    public HotelTheme getById(Long id) {
        HotelTheme ht = hotelThemeMapper.getById(id);
        if("周末好去处".equals(ht.getName())){
            return ht;
        }
        List<Object> list = new ArrayList<>();
        for(long destId:ht.getDestIds()){
            Destination dest = destinationService.getById(destId);
            list.add(dest);
        }
        ht.setDests(list);
        return ht;
    }
}
